﻿/*
 *    Copyright © 2012 FPInst authors
 *
 *      This file is part of the FPInst project 
 *      (for more information, see: http://code.google.com/p/fpinst/).
 *
 *    FPInst is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    FPInst is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with FPInst.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SignalGen
{
    public class Packet
    {
        public enum eType
        {
            GET_VERSION = 0x00,
            READ_PROPS = 0x01,

            INITWRITE = 0x03,
            WRITERAM = 0x04,
            STARTGEN = 0x05,
            MANCLK = 0x06,
            FPGAHARDRESET = 0x07,

            SETDAC = 0x08,
            SETFREQ = 0x09,
            SETSWEEP = 0x0A,

            RESET = 0xFF
        };

        public eType Type;
        public byte[] Data;

        public Packet(eType type, byte[] data)
        {
            Type = type;
            Data = data;
        }

        public Packet()
        {
            Type = 0;
            Data = null;
        }

        public byte[] GetData()
        {
            byte[] buf = new byte[Data.Length + 2];
            buf[0] = (byte)Type;
            buf[1] = (byte)Data.Length;
            Array.Copy(Data, 0, buf, 2, Data.Length);
            return buf;
        }

        public void SetData(byte[] buf)
        {
            Type = (eType)buf[0];
            Data = new byte[buf[1]];
            Array.Copy(buf, 2, Data, 0, Data.Length);
        }
    }
}
